package com.study.edoc.service.impl;

import com.study.edoc.common.Pageable;
import com.study.edoc.dao.DocumentDao;
import com.study.edoc.pojo.Document;
import com.study.edoc.service.DocumentService;
import com.study.edoc.vo.DocumentVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional(rollbackFor = Exception.class)
public class DocumentServiceImpl implements DocumentService {

    @Resource
    private DocumentDao documentDao;

    @Override
    public Pageable<DocumentVO> findDocsByPage(int cid, int page, int size) {
        List<DocumentVO> docList = documentDao.selectDocsByPage(cid, page, size);
        int total = documentDao.selectDocTotalCount(cid);
        Pageable<DocumentVO> pageable = new Pageable<>(page,size,total,docList);
        return pageable;
    }


    @Override
    public int modifyDoc(Document doc) {
        return documentDao.updateDoc(doc);
    }

    @Override
    public int deleteDocById(int id) {
        return documentDao.deleteDocById(id);
    }

    @Override
    public DocumentVO findDocById(int id) {
        return documentDao.selectDocById(id);
    }

    @Override
    public int addDoc(Document doc) {
        return documentDao.insertDoc(doc);
    }
}
